//
//  DiarysItemView.swift
//  MyDiary2025
//
//  Created by 罗万能 on 2025/6/25.
//

import SwiftUI

struct DiarysItemView: View {
    var  diary: DiaryModel
    @State var isShowDetail: Bool = false
    var body: some View {
        ZStack(alignment: .leading) {
            RoundedRectangle(cornerRadius: 12)
                .foregroundStyle(.back.opacity(1))
                .shadow(radius: 3)
            VStack(alignment: .leading) {
                HStack(alignment:.firstTextBaseline) {
                    Text(diary.title)
                        .font(.title)
                        .foregroundColor(Color("title"))
                    Spacer()
                    Image(systemName: diary.isSecret ? "lock.shield" : "lock.open")
                        .foregroundStyle(Color("body"))
                        .onTapGesture {
                            diary.isSecret.toggle()
                        }
                }.padding(.bottom,10)
                HStack(alignment: .center) {
                    Text("类别：\(diary.category.categoryName)")
                        .font(.body)
                        .foregroundStyle(.body)
                        .padding(.trailing,15)
                    Text(diary.weather.chineseDescription)
                        .foregroundStyle(diary.weather.color)
                    diary.weather.image
                        .foregroundStyle(diary.weather.color)
                }
                HStack{
                    Text(diary.createDate.viewDate)
                    Image(systemName: "mappin.and.ellipse.circle")
                    Text(diary.locationDescription)
                    
                    
                } .font(.footnote)
                    .foregroundStyle(Color("footboot"))
                
            }
            .padding()
            .sheet(isPresented: $isShowDetail, content: {
                DiaryDetailView(diary: diary)
                
            })
            .onTapGesture {
                isShowDetail.toggle()
            }
            //        .background(Color("back"))
        }
    }
}

#Preview {
    DiarysItemView(diary: DiaryModel.debugData)
}
